package day52.basic.controller;

import day52.basic.domain.dto.WechaBinderDto;
import day52.basic.domain.dto.WechatRegisterDto;
import day52.basic.domain.dto.LoginDto;
import day52.basic.service.ILoginService;
import day52.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private ILoginService loginService;

    /**
     * 账户登陆
     * @param dto
     * @return
     */
    @PostMapping("/account_login")
    public AjaxResult loginByAccount(@RequestBody @Valid LoginDto dto){
        return loginService.loginByAccount(dto);
    }

    /**
     * 微信登陆
     * @param map
     * @return
     */
    @PostMapping("/wechat_login")
    public AjaxResult loginByWechat(@RequestBody Map<String,String> map){
        return loginService.loginByWechat(map);
    }

    /**
     * 微信绑定
     * @param dto
     * @return
     */
    @PostMapping("/wechat_binder")
    public AjaxResult binderByWechat(@RequestBody @Valid WechaBinderDto dto){
        return loginService.binderByWechat(dto);
    }

    /**
     * 微信绑定注册
     * @param dto
     * @return
     */
    @PostMapping("/wechat_register")
    public AjaxResult registerByWechat(@RequestBody @Valid WechatRegisterDto dto){
        return loginService.registerByWechat(dto);
    }

}
